package com.stanford.ml;

import com.stanford.ml.svm.Problem;

/**
 * Measures SVM classifier performance
 * @author Fatih Sunor
 *
 */
public class ClassifierMeasures {

	private Problem _p;
	private int[] _predicted;

	/**
	 * Constructor for classifier performance metrics
	 * @param problem
	 * @param predicted
	 * @param catnum
	 */
	public ClassifierMeasures(Problem problem, int [] predicted) {
		_p = problem;
		_predicted = predicted;
	}
	
	/**
	 * Calculates the accuracy of the classification
	 * @return a double value between 0 and 1
	 */
	public double Accuracy() {
		int ret = 0;
		for (int i=0; i<_p.getL(); i++) {
			if (_p.getY()[i] == _predicted[i]) {
				ret++;
			}
		}
		return (double)ret/_p.getL();
	}
}
